<template>
    <div id="formTime">
        <table>
            <tr>
                <th>输入</th>
                <th>输入格式</th>
                <th>输出格式</th>
                <th>输出结果</th>
            </tr>
            <tr v-for="(item, index) in timeList" :key="index">
                <td>{{item.time}}</td>
                <td>{{item.type}}</td>
                <td>{{item.out}}</td>
                <td>{{formTime(item.type, item.out, item.time)}}</td>
            </tr>
        </table>
    </div>
</template>
<script>
import formTime from "../assets/js/formTime.js";

export default {
  name: "formTime",
  components: {},
  data() {
    return {
      timeList: [
        // 时间戳转时间
        {
          time: 1539221985,
          type: "Timestamp-S",
          out: "YYYY-MM-DD hh:mm:ss"
        },
        {
          time: 1539221985,
          type: "Timestamp-S",
          out: "YYYY-M-D h:m:s"
        },
        {
          time: 1539221985000,
          type: "Timestamp-MS",
          out: "YYYY-MM-DD hh:mm:ss"
        },
        {
          time: 1539221985000,
          type: "Timestamp-MS",
          out: "YYYY-M-D h:m:s"
        },

        // 时间转时间戳
        {
          time: "2018-10-05 06:05:10",
          out: "Timestamp-S",
          type: "YYYY-MM-DD hh:mm:ss"
        },
        {
          time: "2018-10-5 6:5:10",
          out: "Timestamp-S",
          type: "YYYY-M-D h:m:s"
        },
        {
          time: "2018-10-05 06:05:10",
          out: "Timestamp-MS",
          type: "YYYY-MM-DD hh:mm:ss"
        },
        {
          time: "2018-10-5 6:5:10",
          out: "Timestamp-MS",
          type: "YYYY-M-D h:m:s"
        },

        // 时间字符串转时间
        {
          time: "2018年9月10日 10时20分15秒",
          out: "Timestamp-S",
          type: "YYYY-MM-DD hh:mm:ss-s"
        },
        {
          time: "2018年9月10日 10时20分15秒",
          out: "Timestamp-S",
          type: "YYYY-M-D h:m:s-s"
        },
        {
          time: "2018年9月10日 10时20分15秒",
          out: "Timestamp-MS",
          type: "YYYY-MM-DD hh:mm:ss-s"
        },
        {
          time: "2018年9月10日 10时20分15秒",
          out: "Timestamp-MS",
          type: "YYYY-M-D h:m:s-s"
        },
        // 输出时间字符串
        {
          time: "2018-10-05 06:05:10",
          out: "YYYY-M-D h:m:s-s",
          type: "YYYY-MM-DD hh:mm:ss"
        },
        {
          time: "2018-10-5 6:5:10",
          out: "YYYY-MM-DD hh:mm:ss-s",
          type: "YYYY-M-D h:m:s"
        },
      ]
    };
  },
  methods: {
    formTime: formTime
  }
};
</script>
<style scoped>
table {
  margin: 20px;
  border: 1px solid black;
  border-collapse: collapse;
}
td,
th {
  padding: 10px 15px;
  width: 250px;
  text-align: left;
  border: 1px solid black;
}
</style>